package com.doform.android.xianggucheng.popwindow;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.doform.android.xianggucheng.R;
import com.doform.android.xianggucheng.bean.CategoryQueryBean;

import java.util.List;


/**
 * 作者 Y_MS
 * Created by ${APEN} on 2017-08-14.
 * GitHub：https://github.com/cxydxpx
 */

public class PopCategory extends PopupWindow {
    private Context mContext;
    private int mLayoutId;
    private View mConvertView;
    private SparseArray<View> mViews;

    private List<CategoryQueryBean> mDatas;

    public PopCategory(Context context, int mLayoutId) {
        super(context);
        this.mContext = context;
        this.mLayoutId = mLayoutId;
        initView();
    }


    private void initView() {
        mViews = new SparseArray<>();
        mConvertView = LayoutInflater.from(mContext).inflate(mLayoutId, null);
        mConvertView.findViewById(R.id.ll).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PopCategory.this.dismiss();
            }
        });

        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setOutsideTouchable(true);
        this.setContentView(mConvertView);
        this.setBackgroundDrawable(new ColorDrawable(0x00000000));


    }

    public <T extends View> T getView(int viewId) {

        View view = mViews.get(viewId);
        if (view == null) {
            view = mConvertView.findViewById(viewId);
            mViews.put(viewId, view);
        }
        return (T) view;
    }

}
